
export default class storageData {
  static isNotExist(data): boolean {
    return data === null || typeof(data) === 'undefined'
  }
  // map{name,data,maxAge}
  static setLocalStorage(map){
    let now = Number (new Date())
    let data = map.data
    if(map.maxAge){
      map.expires = now + map.maxAge*1000
    }
    let jsonData = JSON.stringify(data)
    localStorage.setItem(map.name,jsonData)
  }
  static getLocalStorage(name){
    let now = Number (new Date())
    let data = JSON.parse(localStorage.getItem(name))
    if(data.expires && data.expires < now){
      localStorage.setItem(name,'')
      return ''
    }else{
      return data
    }
  }
}
